{include file="common/header"/}
<div class="lemo-container">
    <div class="lemo-main">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>题目{:lang('list')}</legend>
            <blockquote class="layui-elem-quote">
                <div class="lemo-table">
                    <div class="layui-inline">
                        <input type="text" id='keys' name="keys" lay-verify="required"
                               placeholder="{:lang('pleaseEnter')}" autocomplete="off" class="layui-input">
                    </div>
                    <a href="javascript:;" class="layui-btn data-add-btn layui-btn-sm" lay-submit="" lay-filter="add"
                       id="search">
                        {:lang('search')}
                    </a>
                    <!--                        <a data-href="{:url('add')}" class="layui-btn layui-btn-sm layui-btn-warm add">{:lang('add')}题目</a>-->
                    <!--                        <a href="javascript:;"  class="layui-btn layui-btn-sm layui-btn-danger" id="delAll">{:lang('delete checked')}</a>-->

                </div>

            </blockquote>

        </fieldset>

        <table class="layui-table" id="list" lay-filter="list"></table>
    </div>
</div>


<script type="text/html" id="action">
    {if condition="$status eq 1"}
    <a class="layui-btn layui-btn-xs layui-btn-danger">已选择过题目</a>
    {else /}
    <a data-href="{:url('select_topic')}?id={{d.id}}" class="layui-btn  layui-btn-xs" lay-event="select-topic">选择题目</a>
    {/if}
    <!--    <a  class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>-->
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <!--        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
        <!--        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
        <!--        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    </div>
</script>
{include file="common/footer"/}
<script>
    var tableIn = null;
    layui.config({
        base: "/static/admin/js/",
        version: true
    }).extend({
        Admin: 'Admin',
    }).use(['table', 'Admin'], function () {
        var $ = layui.jquery,
            table = layui.table;
        var tablelist = $('.layui-table').attr('id');
        var iframe=null;

        /* 成功
            * @param title
            * @returns {*}
        */

        function success (title) {
            layer.msg(title, {icon: 1, shade: this.shade, scrollbar: false, time: 2000, shadeClose: true});
        };

        /**
         * 失败
         * @param title
         * @returns {*}
         */

        function error(title) {
            layer.msg(title, {icon: 2, shade: this.shade, scrollbar: false, time: 3000, shadeClose: true});
        };

        tableIn = table.render({
            elem: '#list',
            url: '{:url("student_select")}',
            method: 'post',
            title: '用户数据表',
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板

            defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }],
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'id', title: 'ID', width: 80, type: 'numbers', fixed: true, sort: true},
                {field: 'title', title: '标题', width: 200},
                {field: 'desc', title: '描述', width: 400},
                {field: 'create_time', title: '创建时间', width: 180, templet: '#create_time'},
                // {field: 'update_time', title: '更新时间', width: 180, templet: '#update_time'},

                {title: '操作', width: 150, toolbar: '#action', align: "center"},

            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });

        table.on('tool(' + tablelist + ')', function (obj) {
            var data = obj.data;
            var url = $(this).attr('data-href');
            if (obj.event === 'select-topic') {

                layer.confirm('是否确认选择？', function (index) {
                    loading = layer.load(1, {shade: [0.1, '#fff']});

                    $.post(url ? url : 'delete', {id: data.id}, function (res) {
                        layer.close(loading);
                        if (res.code > 0) {
                            if (iframe) {
                                layer.closeAll();
                            }
                            success(res.msg);
                            setTimeout(function () {
                                location.reload()
                            }, 1500)
                        } else {
                            success(res.msg);
                        }
                    });
                });

            }


        });

    });


</script>